home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / actlib17.arj / TOOLS.ARJ / TMPPATH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-30  |  1.4 KB  |  70 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "tools.h"
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <dos.h>
  7.  
  8.  
  9. /***
  10.  *
  11.  *  Function   :    gettmppath
  12.  *
  13.  *  Topics     :    Transforms a filename into a full pathname
  14.  *                  relative to temporary directory.
  15.  *
  16.  *  Decisions   :  Temporary directory is first searched
  17.  *                 into environment variable 'TEMP',
  18.  *                 after into environment variable 'TMP'.
  19.  *                 If none are defined, 'C:\' is assumed.
  20.  *
  21.  *  Parameters :    in/out  char *filename    filename
  22.  *
  23.  *  Return     :    pointer to filename
  24.  *
  25.  ***/
  26.  
  27. char *gettmppath( char *filename )
  28. {
  29.  char *ptr;
  30.  
  31.  ptr = getenv( "TEMP" );
  32.  if ( ! ptr || ! *ptr ) ptr = getenv( "temp" );
  33.  if ( ! ptr || ! *ptr ) ptr = getenv( "TMP" );
  34.  if ( ! ptr || ! *ptr ) ptr = getenv( "tmp" );
  35.  
  36.  if ( ! ptr || ! *ptr ) putenv( "TEMP=C:\\" );
  37.  
  38.  {
  39.   char buffer[_MAX_PATH];
  40.   strcpy( buffer, filename );
  41.   _makepath( filename, "", ptr, buffer, "");
  42.   fnreduce( filename );
  43.  }
  44.  
  45.  if ( ! ptr || ! *ptr ) putenv( "TEMP=" );
  46.  
  47.  return filename;
  48. }
  49.  
  50.  
  51. #ifdef MAIN
  52.  
  53. #include <stdio.h>
  54. #include <conio.h>
  55. void main( void )
  56.  
  57. {
  58.  char f[_MAX_PATH];
  59.  
  60.  strcpy( f, "abc.ext" );
  61.  
  62.  putenv( "TEMP=e:\\tmp" );
  63.  putenv( "TMP=c:\\tmp" );
  64.  clrscr();
  65.  printf( "%s\n", gettmppath(f) );
  66.  getch();
  67. }
  68.  
  69. #endif
  70.